import { type WebSocketClient , StandardWebSocketClient } from '../lib/websocket.ts';
import { encode } from 'https://deno.land/std@0.65.0/encoding/utf8.ts';
import {  green} from 'https://deno.land/std@0.65.0/fmt/colors.ts';
const endpoint = Deno.args[0] || 'ws://127.0.0.1:8888';

const ws: WebSocketClient = new StandardWebSocketClient(endpoint);
ws.on('open', function () {
	console.log('WebSocket opened');
	Deno.stdout.write(encode(green("ws connected! (type 'close' to quit)\n")));
	Deno.stdout.write(encode('> '));
});
ws.on('message', function (message: string) {
	Deno.stdout.write(encode(`${message}\n`));
	Deno.stdout.write(encode('> '));
});

 